@include('public.page_styles')
<link rel="stylesheet" href="{{ asset("/AdminLTE/bower_components/bootstrap-daterangepicker/daterangepicker.css") }}">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
@include('public.top')
<!-- Left side column. contains the logo and sidebar -->
@include('public.sidebar')
<!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                {{ trans('message.exchangeCode') }}
                <small>{{ trans('message.add') }}</small>
            </h1>
            <ol class="breadcrumb">
                <li><a ><i class="fa fa-dashboard"></i> {{ trans('message.home') }}</a></li>
                <li><a href="{{ url('exchangeCode/list') }}"> {{ trans('message.exchangeCode') }} {{ trans('message.list') }}</a></li>
                <li class="active">{{ trans('message.exchangeCode') }}{{ trans('message.add') }}</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <!-- Horizontal Form -->
                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title"> {{ trans('message.add') }}</h3>
                            <div class="box-tools">
                                <div class="btn-group pull-right" style="margin-right: 10px">
                                    <a href="{{ url('exchangeCode/list') }}" class="btn btn-sm btn-default"><i class="fa fa-list"></i>&nbsp; {{ trans('message.list') }}</a>
                                </div>
                                <div class="btn-group pull-right" style="margin-right: 10px">
                                    <a class="btn btn-sm btn-default form-history-back" onclick="goBack()" ><i class="fa fa-arrow-left"></i>&nbsp;{{ trans('message.history-back') }}</a>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-header -->
                        <!-- form start -->
                        <form name="createForm" action="{{url('exchangeCode/')}}" method="post"  class="form-horizontal" onSubmit="return confirm();" >
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">所属网点</label>
                                    <div class="col-sm-8">
                                        <span class="form-control-require">*</span>
                                        <select class="form-control" name="bank_show_id" required>
                                            {{--<option value="0" selected>全部通用</option>--}}
                                            @if($bankShop)
                                                @foreach($bankShop as $value)
                                                    <option value="{{ $value->id }}">{{ $value->shopName }}</option>
                                                @endforeach
                                            @endif
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group ">
                                    <label for="code_dec" class="col-sm-2 control-label">兑换码张数</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" id="exchangCodeNum" name="exchangCodeNum" placeholder="输入兑换码张数" value="{{ old('exchangCodeNum') }}" onkeyup= "if(! /^[0-9]{1,}$/.test(this.value)){alert('只能输入数字');this.value='';}" >
                                    </div>
                                </div>

                                <div class="form-group ">
                                    <label for="code_dec" class="col-sm-2 control-label">描述</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" id="code_dec" name="code_dec" placeholder="描述" value="{{ old('code_dec') }}"  >
                                    </div>
                                </div>

                                <div class="form-group {!! !$errors->has('validity') ?: 'has-error' !!}">
                                    <label for="validity" class="col-sm-2 control-label">使用有效期</label>
                                    <div class="col-sm-5">
                                        <div id="reportrange" class="dateRange" >
                                            <input type="text" class="form-control " id="searchDateRange" name="validity" placeholder="无限期输入：36">
                                        </div>
                                        @if($errors->has('validity'))
                                            @foreach($errors->get('validity') as $message)
                                                <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{{$message}}</label></br>
                                            @endforeach
                                        @endif
                                    </div>
                                    <span style="line-height: 34px;font-size: 10px;">例如：2017-09-26 00:00:00 - 2017-10-08 23:00:00 或者 月份值（1）</span>
                                </div>

                                <div class="form-group">
                                    <label for="remark" class="col-sm-2 control-label">备注</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" id="remark" name="remark" placeholder="有效期一个月" value="{{ old('remark') }}"  >
                                    </div>
                                </div>

                            </div>
                            <!-- /.box-body -->
                            <div class="box-footer">
                                <div class="col-sm-2">
                                </div>
                                <div class="col-sm-8">
                                    <div class="btn-group pull-right">
                                        <button type="button" class="btn btn-info pull-right btn-js-form-submit" >提交</button>
                                    </div>
                                    <div class="btn-group pull-left">
                                        <button type="reset" class="btn btn-warning">撤销</button>
                                    </div>
                                </div>
                            </div>
                            <!-- /.box-footer -->
                        </form>
                    </div>
                    <!-- /.box -->
                </div>
                <!--/.col (right) -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
@include('public.bottom')

<!-- Control Sidebar -->
{{--@include('public.aside')--}}
<!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

@include('public.javascript')
{{--<script src="{{ asset ("/AdminLTE/bower_components/fastclick/lib/fastclick.js") }}" type="text/javascript"></script>--}}
<script src="{{ asset ("/AdminLTE/bower_components/moment/min/moment.min.js") }}" type="text/javascript"></script>
<script src="{{ asset ("/AdminLTE/bower_components/bootstrap-daterangepicker/daterangepicker.js") }}" type="text/javascript"></script>

<script type="text/javascript">
    $(function(){
        $('#reportrange').daterangepicker({
            showDropdowns : true,
            showWeekNumbers : false, //是否显示第几周
//            opens : 'right', //日期选择框的弹出位置
            buttonClasses : [ 'btn btn-default' ],
            applyClass : 'btn-small btn-primary blue',
            cancelClass : 'btn-small',
            format : 'YYYY-MM-DD HH:mm:ss', //控件中from和to 显示的日期格式
            separator : ' to ',
            locale : {
                applyLabel : '确定',
                cancelLabel : '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1
            }
        }, function(start, end, label) {//格式化日期显示框

            $('#reportrange input').val(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'));
        });

    });





    jQuery(function ($) {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
        });


        @if(session()->has('fail'))
          alertMess("{{session()->get('fail')}}");
        @endif

    });

    function confirm() {
        var validity = $("input[name='validity']").val();

        if(validity.length == 0) {
            alert("有效期不能为空");
            $("#searchDateRange").focus();
            return false;
        }else if(validity.indexOf(' - ') == -1 && isNaN(validity) ){
            alert('必须填写数字或者日期区间');
            $("#searchDateRange").focus();
            return false;
        }else{
            return true;
        }
    }


    var _ajaxSubmitSending = false;
    $(".btn-js-form-submit").click(function (e) {
        if (_ajaxSubmitSending) {
            return;
        } else {
            _ajaxSubmitSending = true;
            _loadingFuc();
        }

        $('form[name="createForm"]').submit();
        _ajaxSubmitSending = false;
        setTimeout(function(){
            $.unblockUI();
        }, 1500);
    });





</script>

</body>
</html>
